﻿using Ny.CenterServers.Configuration;
using Ny.CenterServers.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace Ny.CenterServers.EntityFrameworkCore
{
    /// <summary>
    /// 用于程序包控制台命令 codefirst
    /// </summary>
    /* This class is needed to run EF Core PMC commands. Not used anywhere else */
    public class CenterServersDbContextFactory : IDesignTimeDbContextFactory<CenterServersDbContext>
    {
        public CenterServersDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<CenterServersDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            DbContextOptionsConfigurer.Configure(
                builder,
                configuration.GetConnectionString(CenterServersConsts.ConnectionStringName)
            );

            return new CenterServersDbContext(builder.Options);
        }
    }
}